'use strict'
import Player from './player'
import BasicInfo from './basicInfo'
let localStorage = window.localStorage

class PlayerHandle {
    constructor() {}

    create(name) {
        let basicInfo = new BasicInfo({
            name: name
        })
        let player = new Player({
            basicInfo: basicInfo,
            name: name
        })
        player = new Player(player)
        player.save()
        return player
    }

    getPlayer(name) {
        let content = localStorage.getItem(name)
        if (content) {
            let player = JSON.parse(content)
            player = new Player(player)
            return player
        }
        return null
    }

    initPlayer(data) {
        let player = new Player(data)
        player.initPlayer()
        return player
    }

}

let playerHandle = new PlayerHandle()

module.exports = playerHandle